<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-3.3.1.js"></script>
    <script>

        function delbook(id) {
            if(confirm("你确认删除吗")){
                $.ajax({
                    url:"book/delBook",
                    data:{"id":id},
                    Type:"post",
                    success:function (data) {
                        location.href="login.html";
                    }
                })

            }

        }
        function jump(){
            location.href="add.html";
        }
        $(function () {
            $.ajax({
                url:"book/findAll",
                Type:"post",
                success:function (data) {
                   var list="";
                    list+='  <tr> <th>书号</th>\n' +
                        '       <th>书名</th>\n' +
                        '       <th>作者</th>\n' +
                        '       <th>时间</th>\n' +
                        '       <th>类型</th>\n' +
                        '       <th>操作</th></tr>';
                    for (var i = 0; i <data.length ; i++) {
                        var obj = data[i];
                        list+=' <tr>\n' +
                            '        <td>'+obj.id+'</td>\n' +
                            '        <td>'+obj.name+'</td>\n' +
                            '        <td>'+obj.author+'</td>\n' +
                            '        <td>'+obj.fromatTime+'</td>\n' +
                            '        <td>'+obj.bookMeg+'</td>\n' +
                            '        <td><a href="javascript:void(0)" onclick="delbook('+obj.id+')">删除</a> </td>\n' +
                            '    </tr>';
                    }
                     list+='  <tr><td colspan="6" align="center"> <input type="button" value="添加" id="btn_add" onclick="jump()"></td></tr>';
                    $("#table").prepend(list);
                }
            })
        })
    </script>
</head>
<body>
<form>
<table align="center" border="2px" id="table">


</table>

</form>
</body>
</html>